const app = getApp()
const $api = require('../../api/index')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        navTop: app.globalData.navTop,
        time: 0,
        orderId:'',
        timeData: {},
    },
    onChange(e) {
        this.setData({
          timeData: e.detail,
        });
      },
      goBack() { //返回
        wx.navigateBack({
            delta: 5
        })  
    },
    delayed(){
        wx.navigateTo({
            url: `../appointmentOrder/appointmentOrder?orderId=${this.data.orderId}`
        })
    },
      endAppointment(){//结束预约
        let data = {
            trade_no:this.data.orderId
        }
        $api.subscribeFinish(data).then((res) => {
            wx.showToast({
              title: '结束预约成功!',
              duration: 3000
            })
            this.goBack()
        })
      },
      onFinish(e){//倒计时结束

      },
      start() {
        const countDown = this.selectComponent('.control-count-down');
        countDown.start();
      },
    
      pause() {
        const countDown = this.selectComponent('.control-count-down');
        countDown.pause();
      },
    
      reset() {
        const countDown = this.selectComponent('.control-count-down');
        countDown.reset();
      },
      getsubscribeDetail(orderId) { //根据订单号获取预约时间
        let data = {
            trade_no: orderId,
        }
        $api.subscribeDetail(data).then((res) => {
            this.setData({
                time: res.data.surplus_time*60*1000,
                orderId: res.data.trade_no
            })
        })

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getsubscribeDetail(options.orderId)
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})